import { toRaw } from 'vue'
const bpmnInstances = () => (window as any)?.bpmnInstances

// cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.MagicApiConfigTaskEventEnum
export const TaskEventType = {
  created: '任务创建',
  assignment: '任务指派',
  completed: '任务完成',
  cancelled: '任务取消',
}

export function createFormRuleGateWayConfigObject(options, prefix) {

  const formRuleGateWayConfig = Object.create(null)
  formRuleGateWayConfig.event = options.event
  if (options.fields) {
    formRuleGateWayConfig.fields = options.fields.map((field) => {
      return createFormRuleGateWayConfigFieldObject(field, prefix)
    })
  }
  return bpmnInstances().moddle.create(
    `${prefix}:FormRuleGateWayConfig`,
    formRuleGateWayConfig
  )
}


// 创建 监听器的注入字段 实例
function createFormRuleGateWayConfigFieldObject(option, prefix) {
  const { name, stringValue } = option
  const fieldConfig =  { name, stringValue }
  return bpmnInstances().moddle.create(`${prefix}:Field`, fieldConfig)
}
